package com.ruoyi.web;

import com.ruoyi.common.core.controller.BaseController;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.JobSeekerRelation;
import com.ruoyi.system.domain.Seeker;
import com.ruoyi.system.service.IJobSeekerRelationService;
import com.ruoyi.system.service.ISeekerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.stream.Collectors;

@RestController
public class SearchResumeController extends BaseController{

    @Autowired
    private IJobSeekerRelationService jobseekerrelationService;
    private ISeekerService seekerservice;

    @RequestMapping("/searchResumes")
    public AjaxResult searchResumes(@RequestParam String hrId) {
        System.out.println("进入searchResumes函数");
        Long hrIdLong;
        try {
            hrIdLong = Long.parseLong(hrId);
        } catch (NumberFormatException e) {
            return AjaxResult.error("Invalid HR ID format.");
        }

        // 创建一个 JobSeekerRelation 对象，用于传递查询条件
        JobSeekerRelation condition = new JobSeekerRelation();
        condition.setHrId(hrIdLong);

        // 查询所有与该 hrId 相关的 JobSeekerRelation
        List<JobSeekerRelation> relations = jobseekerrelationService.selectJobSeekerRelationList(condition);
        System.out.println("1");
        //List<Seeker> seekers = jobseekerrelationService.findSeekersByHrId(hrIdLong);

//        if (seekers.isEmpty()) {
//            return AjaxResult.error("No seekers found for this HR ID.");
//        } else {
//            return AjaxResult.success("Seekers found.", seekers);
//        }
        // 提取 seekerId 列表
       /* List<Long> seekerIds = relations.stream()
                .map(JobSeekerRelation::getSeekerId)
                .collect(Collectors.toList());
        System.out.println("2");*/
        // 根据 seekerId 列表查询 Seeker 信息
        //List<Seeker> seekers = seekerservice.selectSeekerBySeekerId(seekerIds);

        // 根据 seekerId 列表查询 Seeker 信息
        List<Seeker> seekers = new ArrayList<>();
        /*for (Long seekerId : seekerIds) {
            Seeker seeker = seekerservice.selectSeekerBySeekerId(seekerId);
            if (seeker != null) {
                seekers.add(seeker);
            }
        }

         */
        System.out.println("3");
       if (seekers.isEmpty()) {
            System.out.println("4");
            //return AjaxResult.error("No seekers found for this HR ID.");
           return AjaxResult.success("Seekers found.", seekers);
        } else {
            System.out.println("5");
            return AjaxResult.success("Seekers found.", seekers);
        }


    }
}

